<template>
  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-if="open" v-model="open" width="1200px" append-to-body>

    <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="true">
      <el-form-item label="快速采集:" prop="planName">
        <el-input ref="firstInput" v-model="form.planName"></el-input>
      </el-form-item>
      <el-form-item>
        <!-- <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button> -->
      </el-form-item>
    </el-form>
    <el-card class="box-card" shadow="always">
      <el-table v-loading="dialogLoading" :data="dataSource">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column v-for="(col, index) in columns" :key="index" :label="col.title" align="center"
          :prop="col.dataIndex" :width="col.width" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button type="text" icon="el-icon-delete" @click="itemDelete(scope.row, scope.$index)"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: "quoteForm",
  data() {
    return {
      product: {
        name: '',
        price: '',
        description: '',
      },
      remark: '',
      img_loading: false,
      active: 1,

      open: false,
      title: '加入报价方案',
      form: {
        ktypeid: '',
      },
      rules: {
        productName: [
          { required: true, message: '请输入商品名称', trigger: 'change' }
        ],
        categoryId: [
          { required: true, message: '请选择商品分类', trigger: 'change' }
        ],
        batchNo: [
          { required: true, message: '请输入商品编号', trigger: 'change' }
        ],
      },
      inputWidth: null,
      warehouseList: [],
      dialogLoading: false,
      dataSource: [{ projectName: 'A方案', des: '共2个商品' }],
      locationArr: [],
      tags: [
        { name: '商品基础信息', complete: false },
        { name: '商品价格', complete: false },
        { name: '商品详情描述', complete: false },
      ],
      columns: [
        {
          title: '方案名称',
          dataIndex: 'projectName',
          align: 'center',
          sortable: true
        },
        {
          title: '方案描述',
          dataIndex: 'des',
          align: 'center',
          sortable: true
        }
      ],
      disabled: false,
    }
  },
  methods: {
    add() {
      this.open = true;
    },
    addRow() {
      this.dataSource.push({});
    },
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // Perform form submission logic here
        } else {
          // Handle form validation errors
        }
      });
    },
    cancel() {
      this.open = false;
    },
    itemDelete(row, index) {
      this.dataSource.splice(index, 1);
    },
    getListMatByCode(event, index) {
      const matCode = event.target.value;
      // Perform logic to get mat by code
    },
    getSpaceByWarehouseCode() {
      // Perform logic to get space by warehouse code
    },
    remoteMethod(query, row, index) {
      // Perform remote method logic here
    },
    locationChange(event, row, index) {
      // Handle location change logic here
    },
    uploadRequest() {
      // Perform upload request logic here
    },
    next() {
      this.tags[this.active].complete = true;
      if (this.active < 3) {
        this.active++;
      }
    },
    up() {
      this.active--;
    },
    initColumns() {
      this.getDicts('mx_material_price').then(res => {
        this.columns = (res.data || []).map(item => {
          return {
            title: item.dictLabel,
            dataIndex: item.dictValue,
            width: item.dictLabel.length * 30,
            align: 'center',
            sortable: true
          }
        })
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.tags {
  width: 80%;
  margin: 0 auto;
}

.tags,
.tag {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.tag-num {
  margin-right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background-color: #FF9D93;
  text-align: center;
  color: #fff;
  line-height: 40px;
  font-size: 20px;
}

.tag-name {
  height: 40px;
  line-height: 40px;
  font-size: 20px;
}

.avatar-uploader,
.el-upload {
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 178px !important;
  height: 178px;
}

.avatar-uploader:hover,
.el-upload:hover {
  border-color: #409EFF;
}

.upload-text {
  font-size: 14px;
  color: #8c939d;
  line-height: 178px;
  text-align: center;
  margin: 0 auto;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

.active .tag-num {
  background-color: #FF4D3C;
}
</style>